// home//pages/index_career_detail/index.js
const apis = require('../../../utils/api').apis;
const urls = require('../../../utils/getUrl');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active:false,
    dataArr: [],
    industryId: 0,
    id: 0,
    pages: 1,
    pageNo: 1,
    recommendList: null,
    showModalStatus:'',
    animationData:'',
    valname:'',
    valremark:'',
    number:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      id: options.id
    })
    console.log(this.data.industryId)
    this.getData();
  },
  bindconfirm(e) {
    let val = e.detail.value;
    this.setData({
      valname:val
    })
},
bindconfirm1(e) {
  let val = e.detail.value;
  this.setData({
    valremark:val
  })
},
  sendsign(){
   wx.showLoading({
     title: '报名中',
   })
    if(this.data.valname == ''){
      wx.showToast({
        title: '姓名不能为空',
        icon: 'none',
      })
    } else{
      this.hideModal()
      apis.getSendsign({
        recruitmentId:this.data.id,
        name:this.data.valname,
        remark:this.data.valremark
      }).then(res=>{
        wx.hideLoading()
        if(res.success){
          wx.showToast({
            title: '报名成功',
          })
        } else{
          wx.showToast({
            icon:'none',
            title: '请勿重复报名',
          })
        }
        console.log(res)

      })
    }
    
  },
  getData() {
    apis.recruitmentQueryRecruitmentById({
      id: this.data.id
    }).then(res => {
      let positionDescription=res.data.positionDescription.replace('<img ', '<img style="max-width:100%;height:auto;display:block;margin:10px 0;"') 
      this.setData({
        dataArr: res.data,
        positionDescription:positionDescription,
        industryId:res.data.industryId
      })
    this.getRecommend()
    })
  },
  getRecommend() {
    apis.curriculumReplaceCurriculumRecommend({
      pages: this.data.pages,
      pageSize: 5,
      pageNo: this.data.pageNo,
      industryId: this.data.industryId
    }).then(res => {
      console.log(res.data)
      if(res.data){
        this.setData({
          recommendList: res.data.recommendCurriculumIpage.records,
          pages: res.data.recommendCurriculumIpage.pages,
          pageNo:res.data.recommendCurriculumIpage.current
        })
      }
      console.log(this.data.recommendList)
    })
  },
  signUpNow(){
    var token=wx.getStorageSync('Xd_Token');
    if(token==''||token==null||token==undefined){
      urls.getUrl()
      wx.navigateTo({
        url: '/login/pages/login/index',
      })
      return
    }
    this.showModal()
    let number = wx.getStorageSync('userNumber')
    console.log(number)
    this.setData({
      number:number
    })
  },
    /*显示*/
  showModal: function() {
  console.log('aa')
        var animation = wx.createAnimation({
            duration: 200,
            timingFunction: "linear",
            delay: 0
        })
        this.animation = animation
        animation.translateY(300).step()
        this.setData({
            animationData: animation.export(),
            showModalStatus: true
        })
        setTimeout(function() {
            animation.translateY(0).step()
            this.setData({
                animationData: animation.export()
            })
        }.bind(this), 200)
      },
      hideModal: function() {
        
          var animation = wx.createAnimation({
              duration: 200,
              timingFunction: "linear",
              delay: 0
          })
          this.animation = animation
          animation.translateY(300).step()
          this.setData({
              animationData: animation.export(),
          })
          setTimeout(function() {
              animation.translateY(0).step()
              this.setData({
                  animationData: animation.export(),
                  showModalStatus: false
              })
          }.bind(this), 200)
      },
  // 报名事件
  btnSign(){
    this.setData({
      active:true
    })
  },
  guansign(e){
    // e.stopPropagation(); 
    this.setData({
      active:false
    })
  },
  changeIt(){
    this.getRecommend()
  },

    // 隐藏遮罩层
    hideModal: function() {
        
      var animation = wx.createAnimation({
          duration: 200,
          timingFunction: "linear",
          delay: 0
      })
      this.animation = animation
      animation.translateY(300).step()
      this.setData({
          animationData: animation.export(),
      })
      setTimeout(function() {
          animation.translateY(0).step()
          this.setData({
              animationData: animation.export(),
              showModalStatus: false
          })
      }.bind(this), 200)
  },

/*显示*/
  showModal: function() {
      var animation = wx.createAnimation({
          duration: 200,
          timingFunction: "linear",
          delay: 0
      })
      this.animation = animation
      animation.translateY(300).step()
      this.setData({
          animationData: animation.export(),
          showModalStatus: true
      })
      setTimeout(function() {
          animation.translateY(0).step()
          this.setData({
              animationData: animation.export()
          })
      }.bind(this), 200)
    },

    goDetail(e){
      let item=e.currentTarget.dataset.item;
      wx.navigateTo({
        url: '/curriculum/pages/course/index?id='+item.id,
      })
    },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})